package dp;

import java.util.Arrays;

/**
 * 62. 不同路径
 * 创建时间：2024/7/5 下午2:28
 */
public class 不同路径_62 {

    public int uniquePaths(int m, int n) {
        return dfs(m, n - 1)  + dfs(m - 1, n);
    }
    int m1(int m, int n) {
        int[][] dp = new int[m][n];
        for (int i = 1; i < m; i++) {
            dp[i][0] = 1;
        }
        Arrays.fill(dp[0], 1);
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
        return dp[m - 1][n - 1];
    }

    int dfs(int row, int col) {
        if (row == 1 && col == 1) {
            return 1;
        }
        if (row < 1 || col < 1){
            return 0;
        }
        return dfs(row - 1, col) + dfs(row, col - 1);
    }

    public static void main(String[] args) {
        不同路径_62 h = new 不同路径_62();
        int a = h.uniquePaths(12, 23);
        System.out.println(a);
    }
}
